package com.suao.web.controller.report;

import com.suao.common.annotation.Log;
import com.suao.common.core.controller.BaseController;
import com.suao.common.core.domain.AjaxResult;
import com.suao.common.core.page.TableDataInfo;
import com.suao.common.enums.BusinessType;
import com.suao.common.utils.poi.ExcelUtil;
import com.suao.report.domain.VFruitsSalesInfo;
import com.suao.report.service.IVFruitsSalesInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 水果销售统计Controller
 *
 * @author tyz
 * @date 2023-03-02
 */
@RestController
@RequestMapping("/report/fruits")
public class VFruitsSalesInfoController extends BaseController
{
    @Autowired
    private IVFruitsSalesInfoService vFruitsSalesInfoService;

    /**
     * 查询水果销售统计列表
     */
    @PreAuthorize("@ss.hasPermi('report:fruits:list')")
    @GetMapping("/list")
    public TableDataInfo list(VFruitsSalesInfo vFruitsSalesInfo)
    {
        startPage();
        List<VFruitsSalesInfo> list = vFruitsSalesInfoService.selectVFruitsSalesInfoList(vFruitsSalesInfo);
        return getDataTable(list);
    }

    /**
     * 导出水果销售统计列表
     */
    @PreAuthorize("@ss.hasPermi('report:fruits:export')")
    @Log(title = "水果销售统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VFruitsSalesInfo vFruitsSalesInfo)
    {
        List<VFruitsSalesInfo> list = vFruitsSalesInfoService.selectVFruitsSalesInfoList(vFruitsSalesInfo);
        ExcelUtil<VFruitsSalesInfo> util = new ExcelUtil<VFruitsSalesInfo>(VFruitsSalesInfo.class);
        util.exportExcel(response, list, "水果销售统计数据");
    }

    /**
     * 获取水果销售统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('report:fruits:query')")
    @GetMapping(value = "/{salesTime}")
    public AjaxResult getInfo(@PathVariable("salesTime") Date salesTime)
    {
        return success(vFruitsSalesInfoService.selectVFruitsSalesInfoBySalesTime(salesTime));
    }

    /**
     * 新增水果销售统计
     */
    @PreAuthorize("@ss.hasPermi('report:fruits:add')")
    @Log(title = "水果销售统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VFruitsSalesInfo vFruitsSalesInfo)
    {
        return toAjax(vFruitsSalesInfoService.insertVFruitsSalesInfo(vFruitsSalesInfo));
    }

    /**
     * 修改水果销售统计
     */
    @PreAuthorize("@ss.hasPermi('report:fruits:edit')")
    @Log(title = "水果销售统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VFruitsSalesInfo vFruitsSalesInfo)
    {
        return toAjax(vFruitsSalesInfoService.updateVFruitsSalesInfo(vFruitsSalesInfo));
    }

    /**
     * 删除水果销售统计
     */
    @PreAuthorize("@ss.hasPermi('report:fruits:remove')")
    @Log(title = "水果销售统计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{salesTimes}")
    public AjaxResult remove(@PathVariable Date[] salesTimes)
    {
        return toAjax(vFruitsSalesInfoService.deleteVFruitsSalesInfoBySalesTimes(salesTimes));
    }
}
